package com.wangyg.juc.Semaphore.signal;

import java.util.concurrent.Semaphore;

/**
 * Created by wangyg6 on 2018/7/19.
 */
public class ParkingTest {
	private static final Semaphore semaphore = new Semaphore(3);//同时只能三辆车

	public static void park(String msg) throws InterruptedException {
		try {
			semaphore.acquire();
			long time = (long) (Math.random()*1000);
			System.out.println(Thread.currentThread().getName() + "停进来：" + msg);
			Thread.sleep(time);
			System.out.println(Thread.currentThread().getName() + "驶出停车场，耗时：" + time + "ms");
		} finally {
			semaphore.release();
		}
	}
}
